<!DOCTYPE html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">



  
  
    
      
    
    
      
    
  <script src="//cdn.bootcss.com/pace/1.0.2/pace.min.js"></script>
  <link href="//cdn.bootcss.com/pace/1.0.2/themes/blue/pace-theme-flash.min.css" rel="stylesheet">







<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
    
  
  <link href="//cdn.jsdelivr.net/fancybox/2.1.5/jquery.fancybox.min.css" rel="stylesheet" type="text/css">







  

<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Vue,">





  <link rel="alternate" href="/atom.xml" title="TiX" type="application/atom+xml">






<meta name="description" content="记录vue表单数据验证处理。">
<meta name="keywords" content="Vue">
<meta property="og:type" content="article">
<meta property="og:title" content="vue中表单验证">
<meta property="og:url" content="https://gitee.com/L1334101793/vue中表单验证/index.html">
<meta property="og:site_name" content="TiX">
<meta property="og:description" content="记录vue表单数据验证处理。">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2019-04-25T10:05:43.045Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="vue中表单验证">
<meta name="twitter:description" content="记录vue表单数据验证处理。">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    version: '5.1.4',
    sidebar: {"position":"right","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://gitee.com/L1334101793/vue中表单验证/">





  <title>vue中表单验证 | TiX</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-right page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">TiX</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">Stay Hungry, Stay Foolish</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://gitee.com/L1334101793/vue中表单验证/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="TiX">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="TiX">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">vue中表单验证</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-04-25T17:44:31+08:00">
                2019-04-25
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/js/" itemprop="url" rel="index">
                    <span itemprop="name">js</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv"><i class="fa fa-file-o">本文阅读</i>
            <span class="busuanzi-value" id="busuanzi_value_page_pv"></span>人次
            </span>
          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>记录vue表单数据验证处理。<br><a id="more"></a></p>
<h3 id="公共common文件夹下建立validate-js"><a href="#公共common文件夹下建立validate-js" class="headerlink" title="公共common文件夹下建立validate.js"></a>公共common文件夹下建立validate.js</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br></pre></td><td class="code"><pre><span class="line">/* 是否邮编*/</span><br><span class="line"><span class="built_in">export</span> <span class="keyword">function</span> validateMail(rule, value,callback) &#123;</span><br><span class="line">  const reg =/^[1-9][0-9]&#123;5&#125;$/;</span><br><span class="line">  <span class="keyword">if</span>(value==<span class="string">''</span>||value==undefined||value==null)&#123;</span><br><span class="line">    callback();</span><br><span class="line">  &#125;<span class="keyword">else</span> &#123;</span><br><span class="line">    <span class="keyword">if</span> ((!reg.test(value)) &amp;&amp; value != <span class="string">''</span>) &#123;</span><br><span class="line">      callback(new Error(<span class="string">'请输入正确的邮编'</span>));</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">      callback();</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">/* 是否手机号码或者固话*/</span><br><span class="line"><span class="built_in">export</span> <span class="keyword">function</span> validatePhoneTwo(rule, value, callback) &#123;</span><br><span class="line">  const reg = /^((0\d&#123;2,3&#125;-\d&#123;7,8&#125;)|(1[34578]\d&#123;9&#125;))$/;;</span><br><span class="line">  <span class="keyword">if</span> (value == <span class="string">''</span> || value == undefined || value == null) &#123;</span><br><span class="line">    callback();</span><br><span class="line">  &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">    <span class="keyword">if</span> ((!reg.test(value)) &amp;&amp; value != <span class="string">''</span>) &#123;</span><br><span class="line">      callback(new Error(<span class="string">'请输入正确的电话号码或者固话号码'</span>));</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">      callback();</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line">/* 是否固话*/</span><br><span class="line"><span class="built_in">export</span> <span class="keyword">function</span> validateTelphone(rule, value,callback) &#123;</span><br><span class="line">  const reg =/0\d&#123;2&#125;-\d&#123;7,8&#125;/;</span><br><span class="line">  <span class="keyword">if</span>(value==<span class="string">''</span>||value==undefined||value==null)&#123;</span><br><span class="line">    callback();</span><br><span class="line">  &#125;<span class="keyword">else</span> &#123;</span><br><span class="line">    <span class="keyword">if</span> ((!reg.test(value)) &amp;&amp; value != <span class="string">''</span>) &#123;</span><br><span class="line">      callback(new Error(<span class="string">'请输入正确的固话（格式：区号+号码,如010-1234567）'</span>));</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">      callback();</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line">/* 是否手机号码*/</span><br><span class="line"><span class="built_in">export</span> <span class="keyword">function</span> validatePhone(rule, value,callback) &#123;</span><br><span class="line">  const reg =/^[1][3,4,5,7,8][0-9]&#123;9&#125;$/;</span><br><span class="line">  <span class="keyword">if</span>(value==<span class="string">''</span>||value==undefined||value==null)&#123;</span><br><span class="line">    callback();</span><br><span class="line">  &#125;<span class="keyword">else</span> &#123;</span><br><span class="line">    <span class="keyword">if</span> ((!reg.test(value)) &amp;&amp; value != <span class="string">''</span>) &#123;</span><br><span class="line">      callback(new Error(<span class="string">'请输入正确的电话号码'</span>));</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">      callback();</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line">/* 是否身份证号码*/</span><br><span class="line"><span class="built_in">export</span> <span class="keyword">function</span> validateIdNo(rule, value,callback) &#123;</span><br><span class="line">  const reg = /(^\d&#123;15&#125;$)|(^\d&#123;18&#125;$)|(^\d&#123;17&#125;(\d|X|x)$)/;</span><br><span class="line">  <span class="keyword">if</span>(value==<span class="string">''</span>||value==undefined||value==null)&#123;</span><br><span class="line">    callback();</span><br><span class="line">  &#125;<span class="keyword">else</span> &#123;</span><br><span class="line">    <span class="keyword">if</span> ((!reg.test(value)) &amp;&amp; value != <span class="string">''</span>) &#123;</span><br><span class="line">      callback(new Error(<span class="string">'请输入正确的身份证号码'</span>));</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">      callback();</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">/* 是否邮箱*/</span><br><span class="line"><span class="built_in">export</span> <span class="keyword">function</span> validateEMail2(rule, value,callback) &#123;</span><br><span class="line">  const reg =/^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]&#123;2,4&#125;$/;</span><br><span class="line">  <span class="keyword">if</span>(value==<span class="string">''</span>||value==undefined||value==null)&#123;</span><br><span class="line">    callback();</span><br><span class="line">  &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">    <span class="keyword">if</span> (!reg.test(value))&#123;</span><br><span class="line">      callback(new Error(<span class="string">'请输入正确的邮箱地址'</span>));</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">      callback();</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="在自己所需的-vue文件中引入全部，或者按需引入"><a href="#在自己所需的-vue文件中引入全部，或者按需引入" class="headerlink" title="在自己所需的.vue文件中引入全部，或者按需引入"></a>在自己所需的.vue文件中引入全部，或者按需引入</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">import &#123;validateIdNo,validatePhone,validateEMail2,validateMail&#125; from <span class="string">'./validate.js'</span></span><br></pre></td></tr></table></figure>
<h3 id="在template中绑定rules-prop写rules里对应的值-见下"><a href="#在template中绑定rules-prop写rules里对应的值-见下" class="headerlink" title="在template中绑定rules,prop写rules里对应的值,见下"></a>在template中绑定rules,prop写rules里对应的值,见下</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br></pre></td><td class="code"><pre><span class="line">&lt;el-form ref=<span class="string">"role"</span> :model=<span class="string">"role"</span> label-width=<span class="string">"120px"</span> :rules=<span class="string">"rules"</span>&gt;</span><br><span class="line">  &lt;el-form-item label=<span class="string">"来信人"</span> prop=<span class="string">"fromName"</span>&gt;</span><br><span class="line">    &lt;el-input v-model=<span class="string">"role.fromName"</span>&gt;&lt;/el-input&gt;</span><br><span class="line">  &lt;/el-form-item&gt;</span><br><span class="line"></span><br><span class="line">  &lt;el-form-item label=<span class="string">"邮箱"</span> prop=<span class="string">"email"</span>&gt;</span><br><span class="line">    &lt;el-input <span class="built_in">type</span>=<span class="string">"email"</span> v-model=<span class="string">"role.email"</span>&gt;&lt;/el-input&gt;</span><br><span class="line">  &lt;/el-form-item&gt;</span><br><span class="line"></span><br><span class="line">  &lt;el-form-item label=<span class="string">"来信目的"</span> prop=<span class="string">"objectiveType"</span>&gt;</span><br><span class="line">    &lt;el-select v-model=<span class="string">"role.objectiveType"</span> class=<span class="string">"handle-select mr10"</span>&gt;</span><br><span class="line">      &lt;el-option v-for=<span class="string">"item in purposeList"</span> :key=<span class="string">"item.id"</span> :label=<span class="string">"item.dict.name"</span> :value=<span class="string">"item.id"</span>&gt;&lt;/el-option&gt;</span><br><span class="line">    &lt;/el-select&gt;</span><br><span class="line">  &lt;/el-form-item&gt;</span><br><span class="line"></span><br><span class="line">  &lt;el-form-item label=<span class="string">"手机号"</span> prop=<span class="string">"phone"</span>&gt;</span><br><span class="line">    &lt;el-input v-model=<span class="string">"role.phone"</span>&gt;&lt;/el-input&gt;</span><br><span class="line">  &lt;/el-form-item&gt;</span><br><span class="line"></span><br><span class="line">  &lt;el-form-item label=<span class="string">"固定电话"</span> prop=<span class="string">"fixedPhone"</span>&gt;</span><br><span class="line">    &lt;el-input v-model=<span class="string">"role.fixedPhone"</span>&gt;&lt;/el-input&gt;</span><br><span class="line">  &lt;/el-form-item&gt;</span><br><span class="line"></span><br><span class="line">  &lt;el-form-item label=<span class="string">"地址"</span> prop=<span class="string">"address"</span>&gt;</span><br><span class="line">    &lt;el-input v-model=<span class="string">"role.address"</span>&gt;&lt;/el-input&gt;</span><br><span class="line">  &lt;/el-form-item&gt;</span><br><span class="line"></span><br><span class="line">  &lt;el-form-item label=<span class="string">"邮编"</span> prop=<span class="string">"postcode"</span>&gt;</span><br><span class="line">    &lt;el-input v-model=<span class="string">"role.postcode"</span>&gt;&lt;/el-input&gt;</span><br><span class="line">  &lt;/el-form-item&gt;</span><br><span class="line"></span><br><span class="line">  &lt;el-form-item label=<span class="string">"标题"</span> prop=<span class="string">"title"</span>&gt;</span><br><span class="line">    &lt;el-input v-model=<span class="string">"role.title"</span>&gt;&lt;/el-input&gt;</span><br><span class="line">  &lt;/el-form-item&gt;</span><br><span class="line"></span><br><span class="line">  &lt;el-form-item label=<span class="string">"内容"</span> prop=<span class="string">"content"</span>&gt;</span><br><span class="line">    &lt;el-input   <span class="built_in">type</span>=<span class="string">"textarea"</span> :rows=<span class="string">"3"</span> v-model=<span class="string">"role.content"</span>&gt;&lt;/el-input&gt;</span><br><span class="line">  &lt;/el-form-item&gt;</span><br><span class="line"></span><br><span class="line">  &lt;el-form-item label=<span class="string">"是否公开"</span> prop=<span class="string">"isPublic"</span>&gt;</span><br><span class="line">    &lt;el-select v-model=<span class="string">"role.isPublic"</span> class=<span class="string">"handle-select mr10"</span>&gt;</span><br><span class="line">      &lt;el-option key=<span class="string">"1"</span> label=<span class="string">"公开"</span> value=<span class="string">"1"</span>&gt;&lt;/el-option&gt;</span><br><span class="line">      &lt;el-option key=<span class="string">"2"</span> label=<span class="string">"不公开"</span> value=<span class="string">"0"</span>&gt;&lt;/el-option&gt;</span><br><span class="line">    &lt;/el-select&gt;</span><br><span class="line">  &lt;/el-form-item&gt;</span><br><span class="line"></span><br><span class="line">  &lt;el-form-item label=<span class="string">"选择部门"</span> prop=<span class="string">"deptId"</span>&gt;</span><br><span class="line">    &lt;el-cascader</span><br><span class="line">      :options=<span class="string">"sponsor"</span></span><br><span class="line">      change-on-select</span><br><span class="line">      :show-all-levels=<span class="string">"false"</span></span><br><span class="line">      v-model=<span class="string">"role.deptId"</span></span><br><span class="line">      placeholder=<span class="string">"选择部门"</span></span><br><span class="line">    &gt;&lt;/el-cascader&gt;</span><br><span class="line">  &lt;/el-form-item&gt;</span><br><span class="line"></span><br><span class="line">  &lt;el-form-item label=<span class="string">"来信人身份证"</span> prop=<span class="string">"fromIdCard"</span>&gt;</span><br><span class="line">    &lt;el-input v-model=<span class="string">"role.fromIdCard"</span>&gt;&lt;/el-input&gt;</span><br><span class="line">  &lt;/el-form-item&gt;</span><br><span class="line"></span><br><span class="line">  &lt;el-form-item&gt;</span><br><span class="line">    &lt;el-button <span class="built_in">type</span>=<span class="string">"primary"</span> @click=<span class="string">"submitFormAdd('role')"</span>&gt;确 定&lt;/el-button&gt;</span><br><span class="line">    &lt;el-button @click=<span class="string">"dialogVisible = false"</span>&gt;取 消&lt;/el-button&gt;</span><br><span class="line">  &lt;/el-form-item&gt;</span><br><span class="line">&lt;/el-form&gt;</span><br></pre></td></tr></table></figure>
<h3 id="rules写在data里-完成。"><a href="#rules写在data里-完成。" class="headerlink" title="rules写在data里,完成。"></a>rules写在data里,完成。</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">rules: &#123;</span><br><span class="line">  fromName: [</span><br><span class="line">    &#123; required: <span class="literal">true</span>, message: <span class="string">"请输入来信人"</span>, trigger: <span class="string">"blur"</span> &#125;</span><br><span class="line">  ],</span><br><span class="line">  email: [&#123; required: <span class="literal">true</span>, message: <span class="string">"请输入邮箱"</span>, trigger: <span class="string">"blur"</span> &#125;,&#123;validator:validateEMail2,trigger:<span class="string">"blur"</span>&#125;],</span><br><span class="line">  objectiveType: [</span><br><span class="line">    &#123; required: <span class="literal">true</span>, message: <span class="string">"请输入来信目的"</span>, trigger: <span class="string">"blur"</span> &#125;</span><br><span class="line">  ],</span><br><span class="line">  phone: [</span><br><span class="line">    &#123; required: <span class="literal">true</span>, message: <span class="string">"请输入来信人手机号"</span>, trigger: <span class="string">"blur"</span> &#125;,&#123;validator:validatePhone,trigger:<span class="string">"blur"</span>&#125;</span><br><span class="line">  ],</span><br><span class="line">  // fixedPhone: [&#123; required: <span class="literal">true</span>, message: <span class="string">"请输入来信人固定电话"</span>, trigger: <span class="string">"blur"</span> &#125;],</span><br><span class="line">  address: [&#123; required: <span class="literal">true</span>, message: <span class="string">"请输入地址"</span>, trigger: <span class="string">"blur"</span> &#125;],</span><br><span class="line">  postcode: [&#123; required: <span class="literal">true</span>, message: <span class="string">"请输入邮编"</span>, trigger: <span class="string">"blur"</span> &#125;,&#123;validator:validateMail,trigger:<span class="string">"blur"</span>&#125;],</span><br><span class="line">  title: [&#123; required: <span class="literal">true</span>, message: <span class="string">"请输入来信题目"</span>, trigger: <span class="string">"blur"</span> &#125;],</span><br><span class="line">  content: [</span><br><span class="line">    &#123; required: <span class="literal">true</span>, message: <span class="string">"请输入来信内容"</span>, trigger: <span class="string">"blur"</span> &#125;</span><br><span class="line">  ],</span><br><span class="line">  isPublic: [&#123; required: <span class="literal">true</span>, message: <span class="string">"必填选项"</span>, trigger: <span class="string">"blur"</span> &#125;],</span><br><span class="line">  status: [&#123; required: <span class="literal">true</span>, message: <span class="string">"选择状态"</span>, trigger: <span class="string">"blur"</span> &#125;],</span><br><span class="line">  deptId: [</span><br><span class="line">    &#123; required: <span class="literal">true</span>, message: <span class="string">"请输入来信部门id"</span>, trigger: <span class="string">"blur"</span> &#125;</span><br><span class="line">  ],</span><br><span class="line">  fromIdCard: [</span><br><span class="line">    &#123; required: <span class="literal">true</span>, message: <span class="string">"请输入来信人身份证号"</span>, trigger: <span class="string">"blur"</span> &#125;,&#123;validator:validateIdNo,trigger:<span class="string">"blur"</span>&#125;</span><br><span class="line">  ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div></div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/wcpay.png" alt="TiX 微信支付">
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/alipay.png" alt="TiX 支付宝">
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Vue/" rel="tag"># Vue</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/关于vue中数据不更新问题总结/" rel="next" title="关于vue中数据不更新问题总结">
                <i class="fa fa-chevron-left"></i> 关于vue中数据不更新问题总结
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/vue中双击按钮出现多次提交情况解决方法/" rel="prev" title="vue中双击按钮出现多次提交情况解决方法">
                vue中双击按钮出现多次提交情况解决方法 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">TiX</p>
              <p class="site-description motion-element" itemprop="description">个人学习记录，涉及前端，分享心得等。</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">21</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">6</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">12</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#公共common文件夹下建立validate-js"><span class="nav-number">1.</span> <span class="nav-text">公共common文件夹下建立validate.js</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#在自己所需的-vue文件中引入全部，或者按需引入"><span class="nav-number">2.</span> <span class="nav-text">在自己所需的.vue文件中引入全部，或者按需引入</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#在template中绑定rules-prop写rules里对应的值-见下"><span class="nav-number">3.</span> <span class="nav-text">在template中绑定rules,prop写rules里对应的值,见下</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#rules写在data里-完成。"><span class="nav-number">4.</span> <span class="nav-text">rules写在data里,完成。</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2019 &mdash; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">TiX</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Mist</a> v5.1.4</div>




        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user">访客</i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      人次
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye">总访问</i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      人次
    </span>
  
</div>








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="//cdn.jsdelivr.net/jquery/2.1.3/jquery.min.js"></script>
  

  
  
    <script type="text/javascript" src="//cdn.jsdelivr.net/fastclick/1.0.6/fastclick.min.js"></script>
  

  
  
    <script type="text/javascript" src="//cdn.jsdelivr.net/jquery.lazyload/1.9.3/jquery.lazyload.min.js"></script>
  

  
  
    <script type="text/javascript" src="//cdn.jsdelivr.net/velocity/1.2.3/velocity.min.js"></script>
  

  
  
    <script type="text/javascript" src="//cdn.jsdelivr.net/velocity/1.2.3/velocity.ui.min.js"></script>
  

  
  
    <script type="text/javascript" src="//cdn.jsdelivr.net/fancybox/2.1.5/jquery.fancybox.pack.js"></script>
  

  
  
    <script type="text/javascript" src="//cdn.bootcss.com/canvas-nest.js/1.0.1/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
